/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.graphics.AdvancedPen;

import fever.utils.Stringifier;

import flash.geom.Matrix;

/**
 * Drawing with new Flash 8 <strong>gradient line</strong> feature.
 *
 * @author Romain Ecarnot
 */
class fvaswing.graphics.FvGradientPen extends AdvancedPen
{
	//-------------------------------------------------------------------------
	// Constants definition
	//-------------------------------------------------------------------------
	
	/** Value used to specify a linear gradient fill. */
	public static var LINEAR : String = "linear";
	
	/** Value used to specify a radial gradient fill. */
	public static var RADIAL : String = "radial";
	
	
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _fillType : String;
	private var _colors : Array;
	private var _alphas : Array;
	private var _ratios : Array;
	private var _matrix : Matrix;
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function FvGradientPen( 
		thickness : Number, 
		fillType : String, colors : Array, alphas : Array, 
		ratios : Array, matrix : Matrix )
	{
		super( null, thickness, null );
		
		_fillType = ( !fillType ) ? FvGradientPen.LINEAR : fillType;
		_colors = colors;
		_alphas = alphas;
		_ratios = ratios;
		_matrix = matrix;
	}
	
	/**
	 * Returns filltype used.
	 * 
	 * @return String
	 */
	public function getFillType() : String
	{
		return _fillType;
	}
	
	/**
	 * Defines filltype to use fo drawing.
	 * 
	 * @param t Valid values are {@link #LINEAR} or {@link #RADIAL}
	 */
	public function setFillType( t : String ) : Void
	{
		_fillType = t;
	}
	
	/**
	 * Returns the array of RGB hexadecimal color values used.
	 * @return Array
	 */
	public function getColors() : Array
	{
		return _colors;
	}
	
	/**
	 * Defines an array of RGB hexadecimal color values that you 
	 * use in the gradient 
	 * @param cs Colors array
	 */
	public function setColors( a : Array ) : Void
	{
		_colors = a;
	}
	
	/**
	 * Returns the array of alpha values used.
	 * @return Array
	 */
	public function getAlphas() : Array
	{
		return _alphas;
	}
	
	/**
	 * Defines an array of alpha values for the corresponding colors 
	 * in the colors array.
	 * @param as Alphas array
	 */
	public function setAlphas( a : Array ) : Void
	{
		_alphas = a;
	}
	
	/**
	 *Returns the array of color ratios used.
	 *@return Array
	 */
	public function getRatios() : Array
	{
		return _ratios;
	}
	
	/**
	 * Defines an array of color distribution ratios.
	 * @param rs Ratios array
	 */
	public function setRatios( a : Array ) : Void
	{
		_ratios = a;
	}
	
	/**
	 * Returns used matrix.
	 * @return Matrix
	 */
	public function getMatrix() : Matrix
	{
		return _matrix;
	}
	
	/**
	 * Defines a transformation matrix
	 * @param m Matrix
	 */
	public function setMatrix( m : Matrix ) : Void
	{
		_matrix = m;
	}
	
	/**
	 * Overrides {@code Pen.setTo} to call {@code MovieClip.lineGradientStyle}
	 * method.
	 */
	public function setTo( target : MovieClip ) : Void
	{
		target.lineStyle( _thickness );
		target.lineGradientStyle( _fillType, _colors, _alphas, _ratios, _matrix );
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this );
	}
}